const Webster = require('webster');
const Producer = Webster.producer;
const Task = Webster.task;
const fs = require('fs');

// 函数实现，参数单位 秒 ；
function wait(second) {
    // execSync 属于同步方法；异步方式请根据需要自行查询 node.js 的 child_process 相关方法；
    let ChildProcess_ExecSync = require('child_process').execSync;
    ChildProcess_ExecSync('sleep ' + second);
};

let myProducer = new Producer({
    channel: 'demo_drug',
    dbConf: {
        redis: {
            host: 'redis-12419.c44.us-east-1-2.ec2.cloud.redislabs.com',
            port: 12419,
            password: 'X2AcjziaOOYPppWFOPiP4rmzZ9RFLViv'
        }
    }
});
let ids=fs.readFileSync("./data/ids.txt","utf8").toString().split("\n");

for(let id of ids){
    
let task = new Task({
    spiderType: 'browser',
    engineType: 'playwright',
    browserType: 'firefox',
    url: 'http://www.chinadrugtrials.org.cn/clinicaltrials.searchlistdetail.dhtml?id='+id,
    targets: [
        {
            selector: 'title',
            type: 'text',
            field: 'mybody'
        }
    ],
    actions: [
        {
            type: 'waitAfterPageLoading',
            value: 3501
        }
    ],
    referInfo:{
        id:id
    }
});

myProducer.generateTask(task).then(() => {
    console.log(' done '+id);
    // process.exit();
});

}

